/**
 * Copyright (C) 2013 AirChina
 *
 * @className:com.airchina.wechat.frontend.processor.main.HistoryFrame
 * @description:
 * 
 * @version:v1.0.0 
 * @author:larry
 * 
 * Modification History:
 * NO   Date         Author      Version     Description
 * -----------------------------------------------------------------
 *     2013-10-17     larry       v1.0.0        create
 *
 *
 */
package com.china.api.wechat.processor.main;

import java.io.Serializable;

@SuppressWarnings("serial")
public class HistoryFrame implements Serializable{
	private String inMsg;
	private ReplyMapping replyMapping;//动态映射,如果该值不为空将优先使用
	private String replyMappingId;//静态映射使用id
	
	/**
	 * gson反序列化无法支持泛型，此处需要列出所有子类型，并重写get和set方法实现假泛型
	 */
	private TextResponse textResponse;
	private PictureResponse pictureResponse;
	private ImageResponse imageResponse;

	public String getInMsg() {
		return inMsg;
	}

	public void setInMsg(String inMsg) {
		this.inMsg = inMsg;
	}

	public Response getResponse() {
		return textResponse==null?pictureResponse==null?imageResponse:pictureResponse:textResponse;
	}

	public void setResponse(Response response) {
		this.pictureResponse = null;
		this.textResponse = null;
		if(response instanceof TextResponse){
			this.textResponse = (TextResponse)response;
		}else if(response instanceof PictureResponse) {
			this.pictureResponse = (PictureResponse)response;
		}else{
			this.imageResponse = (ImageResponse)response;
		}
	}

	public ReplyMapping getReplyMapping() {
		if(replyMapping == null){
			if(replyMappingId == null){
				return null;
			}
			return ReplyMappingRegister.fetch(replyMappingId);
		}
		return replyMapping;
	}

	/**
	  * @Description:用于保存动态映射，请考虑此对象占用的缓存空间，尽量使用静态映射
	  * @Created:larry 2013-10-18下午1:00:38
	 */
	public void setReplyMapping(ReplyMapping replyMapping) {
		this.replyMapping = replyMapping;
	}

	public String getReplyMappingId() {
		return replyMappingId;
	}

	public void setReplyMappingId(String replyMappingId) {
		this.replyMappingId = replyMappingId;
	}

}